﻿namespace Photon.ModelSample
// this is the sample of explicit interception syntax

// import all the namespaces
import System
import System.Logging
import Photon

// define our interception class
class intercept(IModelProvider):
	// wrapper will ask IoC for these components/services
	_log as ILog
	_policy as INamedProvider[of IExceptionPolicy]
	
	// intercepting the method call
	// note, that this is an ordinary method declaration
	// in Boo syntax
	def GetAllModels(path as string) as (ModelInformation):
		// manually add some good citizenship code
		Enforce.ArgumentNotNullOrEmpty(path, "path")
		// write to the logger
		_log.Debug("Getting models by '${path}'")
		// actual call to the base
		models = _inner.GetAllModels(path)
		
		_log.Debug("We've got ${models.Length} models.")
		return models
	
	// intercept another method
	def SaveModel([Required] model as Model):
		enforce model.Id != Guid.Empty
		_log.Debug("Saving model...")
		retry _policy.Get("RepositoryReliability"):
			_inner.SaveModel(model)